package com.tanglongan.concurrent._basic;

public class Demo21 {
    public static void main(String[] args) {
        Demo21User user = new Demo21User();
        Thread t1 = new Thread(() -> user.updateUsernameAndPassword("b", "bb"));
        t1.setName("A");
        t1.start();


        Thread t2 = new Thread(user::printUsernameAndPassword);
        t2.start();

    }
}

class Demo21User {
    private String username = "a";
    private String password = "aa";

    public void updateUsernameAndPassword(String username, String passord) {
        this.username = username;
        if ("A".equals(Thread.currentThread().getName())) {
            System.out.println("停止A线程");
            Thread.currentThread().suspend();
        }
        this.password = passord;
    }

    public void printUsernameAndPassword() {
        System.out.println("username=" + this.username + ",password=" + this.password);
    }

}